<?php

use Biz\service\brand\BrandCustomCategory;
use Biz\service\brand\Brand;
use Doraemon\tools\ActionLog;
use Doraemon\tools\BlockType;

/**
 * 品牌主页-商品列表
 * Class SpuListAction
 */
class SpuListAction extends ActionPlugin
{
    const USER_LEVEL = self::LEVEL_NOTHING;

    public function main()
    {
        $brandUid = $this->getRequest()->getQuery('uid', 0);
        $categoryId = $this->getRequest()->getQuery('category_id', 0);
        $page = $this->getRequest()->getQuery('page', 1);
        $brandInfo = Brand::getBrandInfosByUid($brandUid);
        if ($brandInfo) {
            $brandInfo = array_shift($brandInfo);
            $res = BrandCustomCategory::getWikiByCategoryId($brandInfo['id'], $this->uid, $page, $categoryId);
            $res['list'] = \Doraemon\tools\StatSign::versionCompatible($res['list'],\Doraemon\tools\StatSign::BRAND_UP_GRADE_VERSION_521, BlockType::TYPE_WIKI, 'wiki');

            $this->setSuccess($res);
        } else {
            $this->setSuccess(['list' => [], 'is_over' => 1]);
        }
        ActionLog::log($this->uid, ['brand_id' => $brandInfo ? $brandInfo['id'] : 0, 'page' => $page, 'category_id' => $categoryId, 'brand_uid' => $brandUid], ActionLog::BIZ_BRAND_DETAIL_GOODS);
    }
}